package si.banst.tecajnice.entitete;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.*;

import static javax.persistence.TemporalType.TIMESTAMP;
import static javax.persistence.EnumType.STRING;

@Entity
@NamedQueries({
		@NamedQuery(name = "vrniVseTecajnice", query = "SELECT t FROM Tecajnica t"),
		@NamedQuery(name = "vrniDatumZadnjeTecajnice", query = "SELECT t.id.datumTecajnice FROM Tecajnica t WHERE t.id.sifraVrsteTecajnice = :sifraVrsteTecajnice ORDER BY t.id.datumTecajnice DESC") })
public class Tecajnica implements Serializable {

	private static final long serialVersionUID = 1L;

	@EmbeddedId
	private TecajnicaID id;

	private String referentZaPreracun;

	@Temporal(TIMESTAMP)
	private Date datumCasPreracuna;

	@Enumerated(STRING)
	private StatusAktivnosti statusAktivnosti;

	@OneToMany(mappedBy = "tecajnica", fetch = FetchType.EAGER)
	private List<Tecaj> tecaji;

	@ManyToOne
	private VrstaTecajnice vrstaTecajnice;

	public Tecajnica() {
		super();
	}

	public TecajnicaID getId() {
		return id;
	}

	public void setId(TecajnicaID id) {
		this.id = id;
	}

	public String getReferentZaPreracun() {
		return referentZaPreracun;
	}

	public void setReferentZaPreracun(String referentZaPreracun) {
		this.referentZaPreracun = referentZaPreracun;
	}

	public Date getDatumCasPreracuna() {
		return datumCasPreracuna;
	}

	public void setDatumCasPreracuna(Date datumCasPreracuna) {
		this.datumCasPreracuna = datumCasPreracuna;
	}

	public StatusAktivnosti getStatusAktivnosti() {
		return statusAktivnosti;
	}

	public void setStatusAktivnosti(StatusAktivnosti statusAktivnosti) {
		this.statusAktivnosti = statusAktivnosti;
	}

	public List<Tecaj> getTecaji() {
		return tecaji;
	}

	public void setTecaji(List<Tecaj> tecaji) {
		this.tecaji = tecaji;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof Tecajnica))
			return false;
		Tecajnica other = (Tecajnica) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	public VrstaTecajnice getVrstaTecajnice() {
		return vrstaTecajnice;
	}

	public void setVrstaTecajnice(VrstaTecajnice vrstaTecajnice) {
		this.vrstaTecajnice = vrstaTecajnice;
	}

	@Override
	public String toString() {
		return "Tecajnica [id=" + id + ", referentZaPreracun="
				+ referentZaPreracun + ", datumCasPreracuna="
				+ datumCasPreracuna + ", statusAktivnosti=" + statusAktivnosti
				+ ", vrstaTecajnice=" + vrstaTecajnice + "]";
	}

}
